﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using System.Data;

namespace Cstudy.DAL
{
    public class Artcles
    {
        public bool AddArtcle(MODEL.artcles artcle)
        {
            SqlParameter[] parms = new SqlParameter[]
            {
                new SqlParameter("@title",artcle.Title),
                new SqlParameter("@content",artcle.Content),
                new SqlParameter("@summary",artcle.Summary),
                new SqlParameter("@authorid",artcle.AuthorID),
                new SqlParameter("@classid",artcle.ClassID),
                new SqlParameter("@tagid",artcle.TagID),
                new SqlParameter("@states",(int)artcle.States)
            };
            return COM.SQLHelper.ExecuteNonQuery("sp_AddArtcle", parms);
        }

        public bool EditArtcle(MODEL.artcles artcle)
        {
            SqlParameter[] parms = new SqlParameter[]
            {
                new SqlParameter("@postid",artcle.postID),
                new SqlParameter("@title",artcle.Title),
                new SqlParameter("@content",artcle.Content),
                new SqlParameter("@summary",artcle.Summary),
                new SqlParameter("@authorid",artcle.AuthorID),
                new SqlParameter("@classid",artcle.ClassID),
                new SqlParameter("@tagid",artcle.TagID),
                new SqlParameter("@states",artcle.States)
            };
            return COM.SQLHelper.ExecuteNonQuery("sp_EditArtcle", parms);
        }

        public DataSet SelectArtcleByID(int id)
        {
            SqlParameter[] parms = new SqlParameter[]
            {
                new SqlParameter("@postid",id)
            };
            return COM.SQLHelper.ExecuteQuery("sp_SelectArtcleByID", parms);
        }

        public bool ArtcleAddReadtime(int id)
        {
            return COM.SQLHelper.ExecuteNonQuery("sp_AddArtcleReadtime");
        }
    }
}
